#!/bin/bash

#------------------------------------------------------------------------------
#Filename:	package-version-info.sh
#Version:	1.1
#Date:	        2013/07/06
#Author:	yuanhui.shi
#Email:	        yuanhui.shi@cs2c.com.cn
#Summary:	02.01系统核心功能-验证软件包的版本信息
#Notes:	        验证系统内所有软件包的版本信息
#Copyright:	China Standard Software Co.,Ltd.
#History:
#	        Version 1.0,2013/07/06
#	        -The first one
#	        Version 1.1,2013/09/09
#	        -Modify the script to satisfy the shell standard
#------------------------------------------------------------------------------


PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

source ../../lib/Echo.sh

function CleanData ()
{
  test -n "`cat /tmp/tmp.result`" 
  EchoInfo "版本信息不正确的软件包有："
  cat /tmp/tmp.result

  rm -rf /tmp/tmp.result
  EchoInfo "package-version-info执行完毕"
}

trap "CleanData" EXIT

FILE1=`rpm -qa`
for VAR in ${FILE1}
do
    [ "`rpm -qi ${VAR} |grep Vendor | awk 'BEGIN {FS=":"} {print $3}'`" == " neokylin" ] && RESULT=1 || RESULT=0
    
#    [ "`rpm -qi ${VAR} |grep Vendor | awk 'BEGIN {FS=":"} {print $3}'`" == " CS2C" ] && RESULT1=1 || RESULT=0

    [ "`rpm -qi ${VAR} |grep Packager | awk 'BEGIN {FS=":"} {print $2}'`" == " NeoKylin Linux" ] && RESULT2=1 || RESULT1=0

    [ ${RESULT} == 1 -a ${RESULT2} == 1 ] && EchoInfo "${VAR} 版本信息正确" &>/dev/null || EchoInfo "${VAR} 版本信息错误" >>/tmp/tmp.result
done

test -z "`cat /tmp/tmp.result`" 
EchoResult "系统已安装的软件包版本信息均正确" 

